
********************************************************************************
* Descriptive statistics
********************************************************************************
clear

* CALL PROGRAM
fiscal

drop if natives!=1

* TRIM VARIABLE
foreach var of varlist totnet_all {
bys year: egen p1`var' = pctile(`var'), p(1)
bys year: egen p99`var' = pctile(`var'), p(99)
gen trim_`var' = 1 if `var'<=p1`var' | `var'>=p99`var'
replace trim_`var' = 0 if trim_`var'==.
drop p1`var' p99`var'
}

* DEFLATE CONTRIBUTIONS	
foreach var of varlist totnet_all oildef {
replace `var' = `var' / deflactor
}

* EXPRESS CONTIRBUTIONS IN MILLIONS
foreach var of varlist totnet_all {
replace `var' = `var'/ 1000000
}


* AVERAGE NFC, CYCLICAL FISCAL BALANCE, IMMMIGRNAT INFLOWS
	// All natives
preserve
collapse (mean) nfc_all totven totpop oildef [iw = pop2013], by(year)
gen share = totven / totpop *100

graph twoway (line nfc_all year, yaxis(1) ytitle("Average fiscal contributions {it:(COP$ million)}")) ///
(line share year, yaxis(2) ytitle("Share of Venezuelan immigrants (%)", axis(2))), ///
xtitle("Year") legend(label(1 "Avg. contributions") label(2 "Immigrant share")) graphregion(color(white)) 
restore

preserve
collapse (mean) nfc_all totven totpop oildef [iw = pop2013], by(year)

graph twoway (line nfc_all year, yaxis(1) ytitle("Average fiscal contributions {it:(COP$ million)}")) ///
(line oildef year, yaxis(2) ytitle("Cyclical fiscal balance: energy {it:(COP$ billion)}", axis(2))), ///
xtitle("Year") legend(label(1 "Avg. contributions") label(2 "Cyclical balance")) graphregion(color(white)) 
restore

	// Natives aged 15 to 64
preserve
collapse (mean) nfc_all_wa totven_wa totpop_wa oildef [iw = pop2013], by(year)
gen share = totven_wa / totpop_wa *100

graph twoway line nfc_all_wa year, yaxis(1) ytitle("Average fiscal contributions" "{it:(COP$ million, 2018 equivalent)}") ylabel(, angle(0)) ///
|| line share year, yaxis(2) ytitle("Venezuelan immigrants / total population (%)", axis(2)) ylabel(, axis(2) angle(0)) ///
xtitle("") legend(label(1 "Avg. contributions") label(2 "Immigrant share")) ///
ylabel(, nogrid) graphregion(color(white))
restore

preserve
collapse (mean) nfc_all_wa totven_wa totpop_wa oildef [iw = pop2013], by(year)

graph twoway line nfc_all_wa year, yaxis(1) ytitle("Average fiscal contributions" "{it:(COP$ million, 2018 equivalent)}") ylabel(, angle(0)) ///
|| line oildef year, yaxis(2) ytitle("Cyclical fiscal balance: energy" "{it:(COP$ billion, 2018 equivalent)}", axis(2)) ylabel(, axis(2) angle(0)) ///
xtitle("") legend(label(1 "Avg. contributions") label(2 "Cyclical balance")) ///
ylabel(, nogrid) graphregion(color(white))
restore


